package com.xrtn.controller;

import com.xrtn.ApiVersion;
import com.xrtn.bean.TOffInfo;
import com.xrtn.bean.TOrderInfo;
import com.xrtn.service.ICommonService;
import com.xrtn.service.IDoctorService;
import com.xrtn.service.ISysUserService;
import com.xrtn.utils.CodeEnum;
import com.xrtn.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by tu_pei on 2018/3/1.
 */
@Api("医师模块接口")
@Controller
@RequestMapping("/{version}/user")
public class UserController {

    @Autowired
    private IDoctorService doctorService;
    @Autowired
    private ICommonService commonService;
    @Autowired
    private ISysUserService userService;

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: selectUserInfo
     * @Description: 查询大夫个人信息
     */
    @ApiOperation(value = "查询大夫个人信息", notes = "查询大夫个人信息")
    @RequestMapping(value = "/selectUserInfo", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectUserInfo(Integer doctorId) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectUserInfo(doctorId, data));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: selectUserSaleList
     * @Description: 查询大夫业绩列表
     */
    @ApiOperation(value = "查询大夫业绩列表", notes = "查询大夫业绩列表")
    @RequestMapping(value = "/selectUserSaleList", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectUserSaleList(Integer doctorId) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectUserSaleList(doctorId));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: selectStatistics
     * @Description: 统计
     */
    @ApiOperation(value = "统计", notes = "统计")
    @RequestMapping(value = "/selectStatistics", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectStatistics(Integer doctorId, String monthStr) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 返回数据
        return doctorService.selectStatistics(doctorId, monthStr, data);
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: saveDoctorOff
     * @Description: 技师请假接口
     */
    @ApiOperation(value = "技师请假接口", notes = "技师请假接口")
    @RequestMapping(value = "/saveDoctorOff", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "int", required = true, value = "医师id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "offDay", dataType = "string", required = true, value = "请假日期", defaultValue = "2018-03-02"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData saveDoctorOff(TOffInfo offInfo) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(commonService.saveDoctorOff(offInfo));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: saveDoctorOff
     * @Description: 技师撤销请假接口
     */
    @ApiOperation(value = "技师撤销请假接口", notes = "技师撤销请假接口")
    @RequestMapping(value = "/removeDoctorOff", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "int", required = true, value = "医师id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "offDay", dataType = "string", required = true, value = "请假日期", defaultValue = "2018-03-02"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData removeDoctorOff(TOffInfo offInfo) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(commonService.deleteDoctorOff(offInfo));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: selectDoctorOff
     * @Description: 查询可请假的列表
     */
    @ApiOperation(value = "查询可请假的列表", notes = "查询可请假的列表")
    @RequestMapping(value = "/selectDoctorOff", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "int", required = true, value = "医师id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "offDay", dataType = "string", required = true, value = "月份", defaultValue = "2018-03"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectDoctorOff(Integer userId, String offDay) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectDoctorRest(userId, offDay));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: selectDoctorOrderList
     * @Description: 获取医师订单列表
     */
    @ApiOperation(value = "获取医师订单列表", notes = "获取医师订单列表")
    @RequestMapping(value = "/selectDoctorOrderList", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "doctorId", dataType = "int", required = true, value = "医师id", defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData selectDoctorOrderList(Integer doctorId) {

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        data.setResults(doctorService.selectDoctorOrderList(doctorId));
        // 返回数据
        return data;
    }

    /**
     * @param @param  userId
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: updateUserPwd
     * @Description: 修改密码
     */
    @ApiOperation(value = "修改密码", notes = "修改密码")
    @RequestMapping(value = "/updateUserPwd", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "doctorId", dataType = "int", required = true, value = "医师id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "userPwd", dataType = "string", required = true, value = "原密码", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "newPwd", dataType = "string", required = true, value = "新密码", defaultValue = "1"),
    })
    @ApiVersion(1)
    @ResponseBody
    public ResponseData updateUserPwd(Integer doctorId, String userPwd, String newPwd) {

        // 创建响应Model
        ResponseData data = new ResponseData();

        Map<String, Object> params = new HashMap<>();
        params.put("doctorId", doctorId);
        params.put("userPwd", userPwd);
        params.put("newPwd", newPwd);
        // 调用Service
        Integer count = doctorService.updateUserPwd(params);
        switch (count) {
            case -1:
                data.setCodeEnum(CodeEnum.CODE_90004);
                break;
            case -2:
                data.setCodeEnum(CodeEnum.CODE_90003);
                break;
            case -3:
                data.setCodeEnum(CodeEnum.CODE_90002);
                break;
            default:
                data.setResults(count);
        }
        // 返回数据
        return data;
    }

    /**
     * 员工评价列表
     *
     * @return
     */
    @ApiOperation(value = "员工评价列表", notes = "员工评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userId", dataType = "int", required = true, value = "用户id", defaultValue = "1"),
    })
    @RequestMapping(value = "/selectUserReplyList",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData selectUserReplyList(Integer userId) {
        ResponseData data = new ResponseData();
        Map<String,Object> params = new HashMap<>();
        params.put("userId",userId);
        params.put("isReply",1);
        List<Map<String,Object>> saleList = userService.selectUserReplyList(params);

        data.setResults(saleList);

        // 返回数据
        return data;
    }
}
